package com.ats.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ats.model.User;
import com.ats.service.GetLeaveServic;
import com.ats.service.StudentService_xh;
import com.ats.service.UserSerivce_xh;
import com.ats.serviceimpl.GetLeaveServiceIml_ty;
import com.ats.serviceimpl.GetNoApprovalServiceImpl;
import com.ats.serviceimpl.StudentServiceImpl_xh;
import com.ats.serviceimpl.UserServiceImpl_xh;
/**
 * 
 * @author TangRain
 *
 */
public class GetLeaveController_ty  extends HttpServlet{
	UserSerivce_xh us = new UserServiceImpl_xh();
	GetLeaveServic  gls =new GetLeaveServiceIml_ty();
	StudentService_xh stus = new StudentServiceImpl_xh();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		resp.setCharacterEncoding("utf8");
		HttpSession session =req.getSession();
		JSONObject os;
		PrintWriter  pw = resp.getWriter();
		int uid =Integer.parseInt(req.getParameter("uid"));		
		int page=Integer.parseInt(req.getParameter("page"));
		int rows=Integer.parseInt(req.getParameter("rows"));
		int usid=us.getUstateByUid(uid);
//辅导员获取学生请假信息
		if(usid==0){
			int iid =((User)session.getAttribute("user")).getIid();
			os=gls.getInstructorLeaveS(iid, page, rows);
			pw.write(os.toString());
//老师获取学生请假信息
		}else if(usid==1){
			int tid =((User)session.getAttribute("user")).getTid();
			os=gls.getTeacherLeaveS(tid,page,rows);
			 pw.write(os.toString());
//学生获取自己的请假信息
		}else if(usid==2){
			int sid =stus.findSidByUid(uid);
			 os=gls.getStuLeaveS(sid,page,rows);
			 pw.write(os.toString());
		}
		pw.flush();
		pw.close();
	}
}
